package geovis.springcloud.demo.stream.producer;

import org.apache.commons.lang.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.logging.Logger;

@EnableBinding(OutputInterface.class)
@EnableScheduling
public class ProducerTask {

    private static Logger logger = Logger.getGlobal();

    @Autowired
    OutputInterface output;

    private int count = 0;

    @Scheduled(initialDelay = 1000, fixedDelay = 500)
    public void produceMessage(){
        count++;
        String message = "producer : count="+count+" "+ DateFormatUtils.format(new Date(),"yyyy-MM-dd HH:mm:ss");
        logger.info(message);
        output.output1().send(MessageBuilder.withPayload(message).build());
    }

}
